{:W('Cate/header')}
{:W('Cate/left')}
    <!--内容部分-->
    <div class="content">
        <div class="title">
            <p>客户管理</p>
            <i class="icon-angle-right"></i>
            <p class="active">客户列表</p>
        </div>
        <div class="admin_list clearfix">
            <div class="main">
                <div class="main_title">
                    <form action="{:U('Client/client')}" method="get">
                    <ul class="clearfix">
                        <li>
                            <span>客户名称</span>
                            <input value="{$param.name}" maxlength="20"  name="name" type="text" >
                        </li>
                        <!--<li>-->
                            <!--<span>服务状态</span>-->
                            <!--<img src="__PUBLIC__/images/i_xiala.png" class="sj icon-sort-down">-->
                            <!--<select name="status">-->
                                <!--<option value="" <if condition="$param['status'] eq ''"> selected </if> >全部</option>-->
                                <!--<option value="0" <if condition="$param['status'] eq '0'"> selected </if> >正常</option>-->
                                <!--<option value="1" <if condition="$param['status'] eq '1'"> selected </if> >过期</option>-->
                            <!--</select>-->
                        <!--</li>-->
                        <button type="submit"><img src="__PUBLIC__/images/seach.png">搜索</button>
                    </ul>
                    </form>
                </div>
                <div class="main_list">
                    <div class="main_list_new">
                        <button id="add_client"><img src="__PUBLIC__/images/add_j.png">新增</button>
                    </div>
                    <div class="main_list_list user_list">
                        <dl>
                            <dt>
                                <span style="width:5%">序号</span>
                                <span style="width:25%;text-align:left;padding-left:20px;">客户名称</span>
                                <span style="width:20%">联系人</span>
                                <span style="width:15%">联系电话</span>
                                <span style="width:10%">用户数</span>
                                <!--<span style="width:10%">当前使用通道数</span>-->
                                <!--<span style="width:10%">剩余可使用通道</span>-->
                                <!--<span style="width:5%">服务状态</span>-->
                                <span style="width:10%">是否启用</span>
                                <span style="width:15%">操作</span>
                            </dt>
                            <volist name="array['companys']" id='row' key="k">
                            <dd>
                                <span style="width:5%">{$k}</span>
                                <span style="width:25%;text-align:left;padding-left:20px;">{$row['name']}</span>
                                <span style="width:20%">{$row['contact']}</span>
                                <span style="width:15%">{$row['tel']}</span>
                                <span style="width:10%">{$row['usernum']}</span>
                                <!--<span style="width:10%">{$row['usechannelnum']}</span>-->
                                <!--<span style="width:10%">{$row['remainchannelnum']}</span>-->
                                <!--<span style="width:5%" class="clolrS active">-->
                                <!--<if condition="$row['status'] eq 0">-->
                                        <!--正常-->
                                    <!--<elseif condition="$row['status'] eq 1"/>-->
                                    <!--<i style="color: #5b6175">过期</i>-->
                                <!--</if>-->
                                <!--</span>-->
                                <span style="width:10%" class="checkbox">
                                    <input type="checkbox" value="{$row.id}" <if condition="$row['active'] eq '1'"> checked </if>/>
                                    <label></label>
                                </span>
                                <span style="width:15%;">
                                    <a href="{:U('Client/client_xq',array('companyId'=>$row['id'],'name'=>$row['name'],'usernum'=>$row['usernum'],'devnum'=>$row['devnum']))}">客户详情</a>
                                </span>
                            </dd>
                            </volist>
                        </dl>
                    </div>
                </div>
                <div class="fy" id="page"></div>
            </div>
        </div>
    </div>
    <!--弹框-->
    <!---->
    <div class="hk"></div>
    <div class="add_group add_client">
        <div class="add_group_title">
            <img src="__PUBLIC__/images/i_guanbi.png" class="icon-remove">新增客户
        </div>
        <div class="add_group_center">
            <ul>
                <li>
                    <span>
                        <i>*</i>客户名称 :
                    </span>
                    <input value="" maxlength="20"  name="name" type="text">
                </li>
                <li>
                    <span>
                        <i>*</i>联系人 :
                    </span>
                    <input value="" maxlength="10" name="contact" type="text">
                </li>
                <li>
                    <span>
                        <i>*</i>联系电话 :
                    </span>
                    <input maxlength="11"  value="" name="tel" type="text">
                </li>
            </ul>
        </div>
        <div class="add_group_btn add_new_client">
            <button>确定</button>
            <button>取消</button>
        </div>
    </div>
</body>
<script>
    $(document).ready(function () {
        //添加子组织
        getPopup($('#add_client'),$('.add_client'));
    })
</script>
<script type="text/javascript">
    // 分页
    layui.use('laypage', function(){
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'page'
            ,count: "<?php echo $totnum; ?>"
            ,limit: "<?php echo $pagecount; ?>"
            ,layout: ['prev', 'page', 'next', 'limit', 'skip']
            ,curr:function(){
                var page = location.search.match(/pageid=(\d+)/);
                return page ? page[1] : 1;
            }()
            ,jump: function(obj,first){  //点击页码出发的事件
                if(first!=true){  //是否首次进入页面
                    var name = "<?php echo $param['name']; ?>";
                    var status = "<?php echo $param['status']; ?>";
                    var _url = "/Client/client?pageid="+obj.curr+"&pagecount="+obj.limit;
                    if(name || status){
                        _url = "/Client/client?pageid="+obj.curr+"&pagecount="+obj.limit+"&name="+name+"&status="+status;
                    }
                    window.location.href = _url;
                }
            }
        });
    });

    $(function(){
        // 添加企业
        $('.add_client button').eq(0).on('click',function(){
            // 获取数据
            var _input = $('.add_client').find('input');
            var _conf = {};
            _input.each(function(i){
                _conf[_input.eq(i).attr('name')] = _input.eq(i).val();
            })
            // 验证数据
            for(var i in _conf){
                if(!$.trim(_conf[i])){
                    layer.msg('请把表单填写完整！',{icon:2,time:2000});
                    return false;
                }
                if(i == 'tel'){   // 验证手机号
                    var _check =  /^1\d{10}$/;
                    if(!_check.test(_conf['tel'])){
                        layer.msg('手机号格式错误！',{icon:2,time:2000});
                        return;
                    }
                }
            }
            $.post("{:U('Client/addEnterprise_post')}",_conf,function(data){
                if(data.result == '0'){
                    layer.msg('新增客户成功！',{icon:1,time:2000},function(){
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }
            })
        })

        // 启用停用
        $('.checkbox').on('click','input',function(){
            var active = '0';  // 不启用
            if($(this).is(':checked')){   // 启用
                active = '1';
            }
            var companyid = $(this).val();
            $.post("{:U('Client/revStopEnterprise_post')}",{'companyid':companyid,'active':active},function(data){
                if(data.result == '0'){
                    layer.msg('操作成功！',{icon:1,time:2000});
                } else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }
            })
        })
    })
</script>
</html>